/*
 * 企业管理
 */

// import { createAPI } from '@/utils/request'

// export const list = data => createAPI('/companys', 'get', data)
// export const add = data => createAPI('/companys', 'post', data)
// export const update = data => createAPI(`/companys/${data.id}`, 'put', data)
// export const remove = data => createAPI(`/companys/${data.id}`, 'delete', data)
// export const detail = data => createAPI(`/companys/${data.id}`, 'get', data)
// export const disabled = data =>
//   createAPI(`/companys/${data.id}/state`, 'post', data)
/*
 * 企业管理
 */

// import { createAPI } from '@/utils/request'
import { createAPI } from '@/utils/request'

// export const list = data => createAPI('/companys', 'get', data)
// export const add = data => createAPI('/companys', 'post', data)
// export const update = data => createAPI(`/companys/${data.id}`, 'put', data)
// export const remove = data => createAPI(`/companys/${data.id}`, 'delete', data)
// export const detail = data => createAPI(`/companys/${data.id}`, 'get', data)
// export const disabled = data => createAPI(`/companys/${data.id}/state`, 'post', data)

// export const getCompanyList = data => createAPI('/companys', 'get', data)

// 获取公司列表
export const getCompanyList = function(data) {
  const stateMapping = new Map([
    [1, '启用'],
    [0, '禁用'],
  ])
  return createAPI('/companys', 'get', data)
    .then(res => ({
      counts: res.data.counts,
      items: res.data.items.map((d, i) => ({
        ...d,
        index: (data.page - 1) * data.pagesize + i + 1,
        state: stateMapping.get(d.state),
      })),
    }))
    .catch(err => err)
}

// 新增企业
export const addCompany = data => createAPI('/companys', 'post', data)
// 删除企业
export const removeCompany  = data => createAPI(`/companys/${data.id}`, 'delete', data)
// 获取单个企业
export const detailCompany = data => createAPI(`/companys/${data.id}`, 'get', data)
// 更新企业
export const updateCompany = data => createAPI(`/companys/${data.id}`, 'put', data)
// 是否禁用
export const disabled = data => createAPI(`/companys/${data.id}/${data.state}`, 'post', data)
